package logic

import (
	"context"
	"errors"
	"home-view/models/mysql"

	"home-view/homerpc/homerpc"
	"home-view/homerpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CollectAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectAddLogic {
	return &CollectAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CollectAddLogic) CollectAdd(in *homerpc.CollectAddRequest) (*homerpc.CollectAddResponse, error) {
	// todo: add your logic here and delete this line

	if in.UserId <= 0 || in.ClassId <= 0 {
		return nil, errors.New("部分用户ID或商品ID无效")
	}

	collect := mysql.Collect{
		UserId:  in.UserId,
		ClassId: in.ClassId,
	}

	if err := collect.CollectAdd(mysql.DB); err != nil {
		return nil, err
	}

	return &homerpc.CollectAddResponse{
		CollectId: int64(collect.ID),
	}, nil
}
